<?php
$cls_id = intval( dPgetParam( $_GET, 'cls_id', 0 ) );

// check permissions for this record
/*
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'currencys', 'edit', $currency_id )) ) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/

require_once( $AppUI->getMasterDataClass ('mdtype' ) );

// load the record data
$msg = '';
$row = new CMdClassification();

$canDelete = $row->canDelete( $msg, $status_id );
if($msg == $AppUI->_('ClassificationDeleteUserError', UI_OUTPUT_JS)) {
	$userDeleteProtect=true;
}

if ($view) {
	$view = ' readonly="true"';
}
else {
	unset($view);
}

if (!$row->load( $cls_id ) && $cls_id > 0) {
	$AppUI->setMsg( 'Classification' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
}
//$type_list=null;

$q = new DBQuery();
$q->addTable('classifications');
$q->addQuery('cls_code');
if (isset($row->cls_code)) {
	$q->addWhere("cls_id != $row->cls_id");
}
$quoteCodeList = $q->loadColumn();
$qCL = '["' . implode('", "', $quoteCodeList) . '"]';

if (!$view) {
	//$type_list = arrayMerge( getTypeList('Customer'), getTypeList('Supplier'));

?>
<form name="MdClsForm" action="?m=masterdata&u=classification" method="post">
<input type="hidden" name="dosql" value="do_aed" />
<input type="hidden" name="cls_id" value="<?=$cls_id?>" />
<?}?>
<table border="0" cellpadding="8" cellspacing="0" width="400px">
<tr>
<td colspan="2" bgcolor="#E0E0E0"><b><?=$AppUI->_('Classification Information')?></td>
</tr>
<tr>
	<td colspan="2">
		<table border="0" cellpadding="0" cellspacing="4" width="100%">
		<tr>
			<td align="right"> * <?=$AppUI->_('Code')?></td>
			<td>
				<input type="text" class="text" name="cls_code" id="cls_code"
				value="<?=@$row->cls_code?>" maxlength="20" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"> * <?=$AppUI->_('Name')?></td>
			<td>
				<input type="text" class="text" name="cls_name" id="cls_name"
					value="<?=@$row->cls_name?>" maxlength="150" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('VAT Exemption')?></td>
			<td><input type="checkbox" name="cls_vat_exemption"
					value="1"  <?=$view?> <?= (@$row->cls_vat_exemption == 1) ? "checked":""?>/>
			</td>
		</tr>
		<? if (!$view) { ?>
		<!--tr>
			<td align="right"><?=$AppUI->_('Type')?></td>
			<td>
				<?// echo arraySelect($type_list,'cls_type',' style="width: 98%"',@$row->cls_type)?>
			</td>
		</tr-->
		<tr>
			<td align="right"><?=$AppUI->_('Active')?></td>
			<td><input type="checkbox" name="cls_active"
					value="1"  <?=$view?> <?= (@$row->cls_active == 1) ? "checked":""?>/>
			</td>
		</tr>
		<? }else { ?>
		<tr>
			<td align="right"><?=$AppUI->_('Type')?></td>
			<td><? echo @$row->getTypeName();?> </td>
		</tr>
		<? } ?>
		</table>
	</td>
</tr>
<tr>
	<td align="center" colspan="2" style="border-top: 1px solid #E0E0E0">
	<? if (!$view) { ?>
		<input type="submit" class="button" value="<?=$AppUI->_('Save')?>"/>
		<input type="button" class="button" value="<?=$AppUI->_('Cancel')?>" onClick="doCloseCls()"/>
	<? } else { ?>
		<input type="button" class="button" value="<?=$AppUI->_('Close')?>" onClick="doCloseCls()"/>
	<? } ?>
	</td>
</tr>
</table>
</form>
<div id="validation_rules" style="visibility: hidden; display: none">
	var fClsCode = new LiveValidation('cls_code');
	fClsCode.add(Validate.Presence );
	fClsCode.add( Validate.Exclusion , {within: <?=$qCL?>});

	var fClsName = new LiveValidation('cls_name');
	fClsName.add(Validate.Presence );

	new Tips($$('.text'));
</div>
